package com.hks360.library.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.hks360.library.R;
import com.hks360.library.common.ResousesConfig;

/**
 * Created by xiaote on 2016/3/17.
 */
public class CheckImageView extends ImageView {
    private int checked_normal;
    private int checked_selected;
    private int enabled_false;
    private int enabled_true;
    private boolean mInvalid = false;
    public boolean ismInvalid() {
        return mInvalid;
    }


    public CheckImageView(Context context) {
        this(context,null);
    }

    public CheckImageView(Context context, AttributeSet attrs) {
        super(context,attrs);
        checked_normal = attrs.getAttributeResourceValue(ResousesConfig.RESOURCES_NAMESPACE,"checked_normal",R.drawable.checkbox);
        checked_selected = attrs.getAttributeResourceValue(ResousesConfig.RESOURCES_NAMESPACE,"checked_selected", R.drawable.checkbox_selected);
        enabled_false = attrs.getAttributeResourceValue(ResousesConfig.RESOURCES_NAMESPACE,"enabled_false",R.color.white);
        enabled_true = attrs.getAttributeResourceValue(ResousesConfig.RESOURCES_NAMESPACE,"enabled_true", R.color.black);
    }

    public void setChecked(boolean checked) {
        mInvalid = checked;
        if (checked) {
            setImageResource(checked_selected);
        } else {
            setImageResource(checked_normal);
        }
    }

    @Override
    public void setEnabled(boolean enabled) {

        if(enabled) {
            setImageResource(enabled_true);
        } else{
            setImageResource(enabled_false);
        }
        super.setEnabled(enabled);
    }

}
